<template>
  <div>
    <Modal
      v-model="ismodal"
      title="新建"
      @on-ok="yes">
      <Form ref="form" :model="newvip" :rules="rule" :label-width="80">
        <FormItem label="链接名称" prop="name">
          <Input type="text" v-model="newvip.name"></Input>
        </FormItem>
        <FormItem label="链接地址" prop="link">
          <Input type="text" v-model="newvip.link"></Input>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="text" size="large" @click="cancel">取消</Button>
        <Button type="primary" size="large" :loading="loading" @click="yes">确定</Button>
      </div>
    </Modal>
    <Button @click="ismodal=true">新建VIP接口</Button>
  </div>
</template>

<script>
  export default {
    name: "my-info",
    props: [],
    data() {
      return {
        ismodal: false,
        loading: false,
        newvip: {
          name: '',
          link: ''
        },
        rule: {
          name: [{required: true, message: '必填', trigger: 'blur'}],
          link: [{required: true, message: '必填', trigger: 'blur'}]
        }
      }
    },
    methods: {
      cancel() {
        this.ismodal = false;
      },
      yes() {
        // this.$refs.form.resetFields();
        // this.$emit('submit');
        // console.log(this.$parent.$data);
        /*console.log(this.$parent.group.push({
          label:this.newvip.name,
          value:this.newvip.link
        }));*/

        this.$refs['form'].validate(val => {
          if (val) {
            /*this.loading=true;
            this.ajax.get('/static/json/json.json').then((data)=>{
              console.log(data);
              this.ismodal=false;
              setTimeout(()=>{this.loading=false;},300);
            });*/
            new Promise((resolve,reject)=>{
              this.$emit('submit',this.newvip);
              resolve()
            }).then(()=>{
              this.ismodal = false;
            })
          }
        })
      }
    }
  }
</script>

<style scoped lang="less">

</style>
